# -*- coding;utf-8 -*-

import os

def get_ip(domain):
	res = os.popen("nslookup {}".format(domain)).read()
	res_list = res.split("s:")[2:]
	eles = []
	for item in res_list:
		item = item.split("\n")[0].strip()
		eles.append(item)
	return eles
if __name__ == "__main__":
	eles = get_ip("redis-service.com-kedacom-ups")
	master = eles[0]
	print "master ->  %r" % master
	slaves = eles[1:]
	print "slaves ->  %r" % slaves
	os.system("redis-trib.py create %s:%s" % (master,"6379"))
	for slave in slaves:
		os.system("redis-trib.py replicate --master-addr %s:%s --slave-addr %s:%s" %(master,"6379",slave,"6379"))
